/* 
 * File:   Character.cpp
 * Author: nstratos
 * 
 * Created on September 20, 2012, 8:13 AM
 */

#include "Character.hpp"
#include "Die.hpp"
#include <string>
#include <vector>
#include <iostream>
using namespace std;

Character::Character(string name) {
    this->level = 1;
    this->name = name;
    vector<int> v = generateRandomAttributes();
    this->strength = v[0];
    this->dexterity = v[1];
    this->constitution = v[2];
    this->intelligence = v[3];
    this->wisdom = v[4];
    this->charisma = v[5];
}

Character::Character(const Character& orig) {
    this->level = orig.level;
    this->name = orig.name;
    this->strength = orig.strength;
    this->dexterity = orig.dexterity;
    this->constitution = orig.constitution;
    this->intelligence = orig.intelligence;
    this->wisdom = orig.wisdom;
    this->charisma = orig.charisma;
}

Character::~Character() {
}

void Character::printCharacterSheet() {
    string line = "----------------------\n";
    cout << line;
    cout << "Name: " << this->name << endl;
    cout << line;
    cout << "STR: " << this->strength << endl;
    cout << "DEX: " << this->dexterity << endl;
    cout << "CON: " << this->constitution << endl;
    cout << "INT: " << this->intelligence << endl;
    cout << "WIS: " << this->wisdom << endl;
    cout << "CHA: " << this->charisma << endl;
    cout << line;
}

vector<int> Character::generateRandomAttributes() {
    vector<int> attributes;
    int atr = 0;
    int rolls[4];
    int position = 0;
    Die d6(6);
    for (int i = 0; i < 6; i++) {
        for (int k = 0; k < 4; k++) {
            rolls[k] = d6.roll();
        }
        int min = rolls[0];
        position = 0;
        for (int j = 1; j < 4; j++) {
            if (rolls[j] < min) {
                min = rolls[j];
                position = j;
            }
        }
        atr = 0;
        for (int z = 0; z < 4; z++) {
            if (z != position) {
                atr += rolls[z];
            }
        }
        attributes.push_back(atr);
    }
    return attributes;
}

string Character::getName() {
    return this->name;
}

